package com.ruyuan.eshop.buyer.controller.trade;

import com.ruyuan.eshop.buyer.domain.request.CreateTradeRequest;
import com.ruyuan.eshop.common.enums.CheckedWay;
import com.ruyuan.eshop.common.domain.vo.TradeVO;
import com.ruyuan.eshop.common.service.trade.order.TradeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 交易控制器
 *
 * @author pwd
 * @version 1.0
 */
@Api(description = "交易接口模块")
@RestController
@RequestMapping("/api/v1.0/trade")
@Validated
public class TradeBuyerController {

    @Autowired
    @Qualifier("tradeServiceImpl")
    private TradeService tradeService;


    @ApiOperation(value = "创建交易")
    @PostMapping(value = "/create")
    public TradeVO create(@RequestBody CreateTradeRequest createTradeRequest) {
        String client = createTradeRequest.getClient();
        String way = createTradeRequest.getWay();
        return this.tradeService.createTrade(client, CheckedWay.valueOf(way));
    }

}
